var s = "a"

var lengthOfLastWord = function(s) {
    var flag = 0;
    var j = 0;
    for(var  i = s.length-1; i>=0; i--) {
        chars = s.charAt(i);
        console.log(chars)
        if(chars != " ") {
            j=1;
            flag++;
        }else if(chars == " " && j==1) {
            return flag
        }
    }
    return flag
}

console.log(lengthOfLastWord(s));